﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace GraphicsEditor
{
    public enum SelectedTool { selectTool, none, drawLine };

    public partial class ToolBox : DockContent
    {
        private SelectTool selectTool;

        public static DrawingTool drawTool = new DrawingTool();

        private static int pixelSize = 10;

        public static int PixelSize
        {
            get { return ToolBox.pixelSize; }
            set { ToolBox.pixelSize = value; }
        }
        public static SelectedTool currentTool = SelectedTool.none;
        public static Color selectedColor = Color.White;
        public ToolBox()
        {
            InitializeComponent();

            selectTool = new SelectTool();
        }

        private void btnNormal_Click(object sender, EventArgs e)
        {
            currentTool = SelectedTool.none;
            drawTool = new DrawingTool();
            /*
            ImageForm content;

            if ((content = getActiveDocument()) != null)
            {
                content.selectTool.deactivateTool();
            }*/
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            currentTool = SelectedTool.selectTool;
            drawTool = new SelectTool();
            
            /*
            ImageForm content;
            
            if ((content = getActiveDocument()) != null)
            {
                currentTool = SelectedTool.selectTool;
                content.selectTool.activateTool();
            }*/
        }

        private ImageForm getActiveDocument()
        {
            ImageForm content = null;

            if (this.ParentForm.Text == "Image Editor Name")
            {
                //got correct parrent, cast it as the correct type and get a ref to the dockpanel
                content = (ImageForm)(((FormMainWindow)this.ParentForm).dockPanel.ActiveDocument);
            }

            return content;
        }

        private void btnDrawLine_Click(object sender, EventArgs e)
        {
            currentTool = SelectedTool.drawLine;
            drawTool = new DrawLine();
        }

        private void btnColor_Click(object sender, EventArgs e)
        {
            colorDialog.AllowFullOpen = true;
            if (colorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                btnColor.BackColor = colorDialog.Color;
                selectedColor = btnColor.BackColor;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            drawTool = new FillTool();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            drawTool = new TextTool();
        }

    }
}
